import requests

from common.root_login import login_token
from config import emp, BASE_URL

# 员工管理类
class employees(object):
    # 新增员工
    @classmethod
    def addemp(cls, header, body):
        url = BASE_URL + emp.addemp
        res = requests.post(url, headers=header, json=body)
        return res

    # 查询员工
    @classmethod
    def getemp(cls, header, id):
        url = BASE_URL + emp.getemp + id
        res = requests.get(url, headers=header)
        return res

    # 修改员工
    @classmethod
    def putemp(cls, header, id, body):
        url = BASE_URL + emp.putemp + id
        res = requests.get(url, headers=header, json=body)
        return res

    # 删除员工
    @classmethod
    def delemp(cls, header, id):
        url = BASE_URL + emp.delemp + id
        res = requests.delete(url, headers=header)
        return res


if __name__ == '__main__':
    # 新增员工
    header = login_token()
    # 管理员
    body = {"username": "aaa", "mobile": "11175188888", "workNumber": "100246"}
    res = employees.addemp(header,body)
    print('新增员工', res.json())
    print('新增员工id', res.json()['data']['id'])
    empid = res.json()['data']['id']

    # 查询员工
    # res1 = employees.getemp(header, id=empid)
    # print('查询员工', res1.json())
    # # print('查询员工返回的部门id',res1.json()['data']['departmentId'])
    # # departid = res1.json()['data']['departmentId']

    # 修改员工
    # putbody = {"username": "aaa", "password": "123456", "departmentId": "aaa"}
    # res2 = employees.putemp(header, id=empid, body=putbody)
    # print('修改员工', res2.json())

    # # 删除员工
    # res3 = employees.delemp(header, id=empid)
    # print("删除员工", res3.json())
